<?php
require_once("functions.php");

if (!isset($session->logged_in) || !$session->logged_in) {
  header("Location: createaccount.php");
}
// Index.php
// Main portal
$userinfo = $session->userinfo;

$newStatus = null;
if(isset($_POST['status'])) {
	if($userkeys = is_integrated_with("twitter", $userinfo['id'])) {
		$Twitter = new SimpleTwitter($twitterConsumerKey, $twitterConsumerSecret, $userkeys['usertoken'], $userkeys['usersecret']);
		$check = $Twitter->postStatus($_POST['status']);
		
		if($check) 
			$newStatus = $_POST['status'];
		else
			$newStatus = "Could not post status to Twitter.";
	}  
}
?>


<?php require_once("header.php"); ?>

<div id="statusUpdater">
  <div class = "box profile">
    <h3>Update Your Status</h3>
	<?php if($newStatus) echo '<h4>Status updated to: '.$newStatus.'</h4>'; ?>
    <form method="post" action="index.php">
      <table>
        <tr><td>
      <textarea name="status" id="status">Enter your status...</textarea>   </td>   
    </tr><td>
        <input type="submit" class="small blue color_button" value="Update" />   </td>   
      </table>
    </form>
  </div>
  <div class = "clear"></div>
</div>
  
<?php require_once("twitter.php"); ?>  

<?php require_once("soundcloud.php"); ?>

<?php
        require 'facebook-php-sdk/src/facebook.php';

        $facebook = new Facebook(array(
          'appId'  => '166511040068674',
          'secret' => '60a50fd29897c6888b560fa21f9414cc',
          'cookie' => true, // enable optional cookie support
        ));
        if ($facebook->getSession()) {
          echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a>';
        } else {
          echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
        }
        
        $facebookSession = $facebook->getSession();

        $me = null;
        // Session based API call.
        if ($facebookSession) {  
          
          try {
          /* $result = $facebook->api(
            '/me/feed/',
            'post',
            array('access_token' => $facebook->getAccessToken(), 'message' => 'Testing an app..')
            );*/
            $uid = $facebook->getUser();
            $me = $facebook->api('/me');
            $me2 = $facebook->api('/me/feed', array('access_token' => $facebook->getAccessToken()));
            
          } catch (FacebookApiException $e) {
            error_log($e);
          }
        }
        if ($me): ?>
        <h3>Facebook image</h3>
        <img src="https://graph.facebook.com/<?php echo $uid; ?>/picture">
        <pre
        <?php 
                print_r($me);
                print_r($me2);
        ?>
        </pre>
        <!---<?php echo $me['name']; ?>
        <?php echo $me['hometown']['name']; ?>
        <?php echo $me['location']['name']; ?>
        <?php echo $me['timezone']; ?>
        <?php echo $me['updated_time']; ?>
        <?php echo $me['link']; ?>
        <?php echo $me['username']; ?>
        -->
        <?php 
          
        endif; 
?>

<?php
require_once("myspace.php");
if (isset($_SESSION['myspaceLoggedIn'])) {
      $myspaceNetwork = new MyspaceNetwork();
      $myspaceNetwork->setMyspaceId(565488126);
      $myspaceStatus = $myspaceNetwork->getStatus();  


echo "
<div class = \"box feedbox margin\">
  <table>
    <tr>
      <td><a href = \"" . $myspaceNetwork->getMyspaceUrl() . "\"><img src = \"layout/myspace_icon.png\" /></a></td>
      <td><h3>MySpace</h3></td>
    </tr>
  
    <tr>
      <td class=\"title\">Status:</td><td>" . $myspaceStatus->getStatus() . "</td>
    </tr>
    <tr>
      <td class=\"titl\">Mood:</td><td><img src =\"" . $myspaceStatus->getMoodIconUrl() . "\"/>" . $myspaceStatus->getMood() . "</td>
    </tr>
    <tr>
        <td class=\"title updated\">Updated:</td><td class=\"update\">" . $myspaceStatus->getdate() . "</td>
    </tr>
  </table>
  <div class = \"clear\"></div>
</div>
";
}
?>

<?php require_once("footer.php"); ?>

